﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Entity.Biz;
using Rison.BusinessFacade.Facade.Biz;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Helper;

namespace Rison.Web.view
{
    public partial class InfoListView : PageDataViewBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            base.dataView = this.gvData;
            base.baseFacade = new InfomationFacade();
            base.hidCurrentPageIndex = this.hidCurPageIndex;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindData();
                GetPic();
            }
        }

        private string curCategory
        {
            get { return string.IsNullOrEmpty(Request.QueryString["t"]) ? "gg" : Request.QueryString["t"]; }
        }

        public string NavUrl
        {
            //get 
            //{
            //    //string _NavUrl = "";

            //    //if (!string.IsNullOrEmpty(Request.QueryString["t"]))
            //    //{
            //    //    string url= Request.QueryString["t"].ToString();
            //    //    if (url = "gg") { _NavUrl = "公告"; }
            //    //}

                
            //    //return _NavUrl ; 
            //    return string.IsNullOrEmpty(Request.QueryString["t"]) ? "gg" : "公告"};
            
            //}
            get { 
                //return string.IsNullOrEmpty(Request.QueryString["t"]) ? "gg" : "公告" ;
                if (!string.IsNullOrEmpty(Request.QueryString["t"]))
                { 
                    string url= Request.QueryString["t"].ToString();
                    if (url=="gg") return "公告";
                    if (url == "jfdt") return "纠风动态";
                    if (url == "jfhc") return "纠风荟萃";
                    if (url == "zxzl") return "专项治理";
                    if (url == "zspy") return "站所评议";
                    if (url == "jftp") return "图片新闻";
                }
                
                return "纠风信息";

            }
        }

        protected override DataSet GetDataSource()
        {
            InfosReaderFacade facade = new InfosReaderFacade(curCategory);

            if (facade.IsNewsCategory)
            {
                return facade.ReadNewsInfos(50);
            }

            return facade.ReadSuqiuInfos(50);
           
        }


        private DataTable GetGongGao()
        {
            DataTable testSource = new DataTable();
            testSource.Columns.Add("InfoId", typeof(System.String));
            testSource.Columns.Add("title", typeof(System.String));
            testSource.Columns.Add("Day", typeof(System.DateTime));

            DataRow dr = null;
            for (int i = 1; i < 30; i++)
            {
                dr = testSource.NewRow();
                dr["InfoId"] = i.ToString(); dr["Day"] = DateTime.Now;
                if (i % 2 == 0)
                    dr["title"] = "祝所有客户“五一”节日快乐!";
                else
                    dr["title"] = "华北电视台管理机制改革咨询项目启动";

                testSource.Rows.Add(dr);
            }
            return testSource;
        }

        private void GetPic()
        {
            InfosReaderFacade facade = new InfosReaderFacade("jftp");//纠风图片
            DataSet dsImages = facade.ReadNewsInfos(6, 15, false); facade = null;

            int i = 0;
            foreach (DataRow row in dsImages.Tables[0].Rows)
            {
                if (row["MediaFileName"].ToString().StartsWith("/"))
                    row["MediaFileName"] = GlobalParams.Instance.NewsImageBaseUrl + row["MediaFileName"].ToString();
                else
                    row["MediaFileName"] = GlobalParams.Instance.NewsImageBaseUrl + "/" + row["MediaFileName"].ToString();

                if (row["MediaFileName"].ToString().Trim() != "")
                {
                    i++;
                }

                if (i == 1)
                    this.Image1.ImageUrl = row["MediaFileName"].ToString();
                else if (i == 2)
                    this.Image2.ImageUrl = row["MediaFileName"].ToString();
                else if (i == 3)
                    this.Image3.ImageUrl = row["MediaFileName"].ToString();  
            }
            dsImages = null;

            if (string.IsNullOrEmpty(this.Image1.ImageUrl))
                this.Image1.ImageUrl = PageGlobalParams.PageUrlBase2 + "/style/image/tpxw1.jpg";
            if (string.IsNullOrEmpty(this.Image2.ImageUrl))
                this.Image2.ImageUrl = PageGlobalParams.PageUrlBase2 + "/style/image/tpxw2.jpg";
            if (string.IsNullOrEmpty(this.Image3.ImageUrl))
                this.Image3.ImageUrl = PageGlobalParams.PageUrlBase2 + "/style/image/tpxw3.jpg";
        }


    }

    
}
